package com.hifar.test.api.constant;

/**
 * 认证错误码枚举
 * 用于标准化Basic认证错误信息
 */
public enum AuthErrorCode {
    
    // 认证头相关错误
    MISSING_AUTH_HEADER("AUTH_001", "认证失败：缺少Authorization头", "请检查请求头中是否包含Authorization字段"),
    INVALID_AUTH_FORMAT("AUTH_002", "认证失败：认证头格式错误", "Authorization头必须以'Basic '开头"),
    INVALID_BASE64("AUTH_003", "认证失败：Base64编码错误", "认证头中的Base64编码格式不正确"),
    
    // 凭据相关错误
    INVALID_CREDENTIALS_FORMAT("AUTH_004", "认证失败：凭据格式错误", "凭据必须为'用户名:密码'格式"),
    EMPTY_CREDENTIALS("AUTH_005", "认证失败：凭据为空", "认证头中的凭据不能为空"),
    
    // 用户名相关错误
    INVALID_USERNAME("AUTH_006", "认证失败：用户名错误", "用户名不正确，请检查用户名"),
    USERNAME_NOT_FOUND("AUTH_007", "认证失败：用户不存在", "指定的用户不存在"),
    
    // 密码相关错误
    INVALID_PASSWORD("AUTH_008", "认证失败：密码错误", "密码不正确，请检查密码"),
    PASSWORD_DECRYPT_ERROR("AUTH_009", "认证失败：密码解密错误", "密码解密失败，请检查密码格式"),
    PASSWORD_FORMAT_ERROR("AUTH_010", "认证失败：密码格式错误", "密码格式不正确"),
    
    // RSA相关错误
    RSA_DECRYPT_ERROR("AUTH_011", "认证失败：RSA解密错误", "RSA解密失败，请检查密码加密方式"),
    RSA_KEY_ERROR("AUTH_012", "认证失败：RSA密钥错误", "RSA密钥配置错误"),
    
    // 系统相关错误
    AUTH_PROCESS_ERROR("AUTH_013", "认证失败：认证处理异常", "认证过程中发生系统异常"),
    AUTH_SYSTEM_ERROR("AUTH_014", "认证失败：系统错误", "认证系统发生内部错误"),
    
    // 权限相关错误
    ACCESS_DENIED("AUTH_015", "认证失败：访问被拒绝", "用户没有访问权限"),
    ACCOUNT_LOCKED("AUTH_016", "认证失败：账户被锁定", "用户账户已被锁定"),
    ACCOUNT_EXPIRED("AUTH_017", "认证失败：账户已过期", "用户账户已过期");
    
    private final String code;
    private final String message;
    private final String suggestion;
    
    AuthErrorCode(String code, String message, String suggestion) {
        this.code = code;
        this.message = message;
        this.suggestion = suggestion;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getMessage() {
        return message;
    }
    
    public String getSuggestion() {
        return suggestion;
    }
    
    /**
     * 创建错误响应对象
     */
    public AuthErrorResponse createErrorResponse() {
        return new AuthErrorResponse(this);
    }
    
    /**
     * 认证错误响应类
     */
    public static class AuthErrorResponse {
        private String code;
        private String message;
        private String suggestion;
        private long timestamp;
        
        public AuthErrorResponse(AuthErrorCode errorCode) {
            this.code = errorCode.getCode();
            this.message = errorCode.getMessage();
            this.suggestion = errorCode.getSuggestion();
            this.timestamp = System.currentTimeMillis();
        }
        
        // Getters and Setters
        public String getCode() {
            return code;
        }
        
        public void setCode(String code) {
            this.code = code;
        }
        
        public String getMessage() {
            return message;
        }
        
        public void setMessage(String message) {
            this.message = message;
        }
        
        public String getSuggestion() {
            return suggestion;
        }
        
        public void setSuggestion(String suggestion) {
            this.suggestion = suggestion;
        }
        
        public long getTimestamp() {
            return timestamp;
        }
        
        public void setTimestamp(long timestamp) {
            this.timestamp = timestamp;
        }
        
        @Override
        public String toString() {
            return "AuthErrorResponse{" +
                    "code='" + code + '\'' +
                    ", message='" + message + '\'' +
                    ", suggestion='" + suggestion + '\'' +
                    ", timestamp=" + timestamp +
                    '}';
        }
    }
}
